<?php

        require_once "../../konfigurasi.php";
        
        koneksi_buka();
        
        if(isset($_POST['materi'])){
                $materi = $_POST['materi'];
        }
        
        if(isset($_POST['kelas'])){
                $kelas = $_POST['kelas'];
        }
        
        if(isset($_POST['hari'])){
                $hari = $_POST['hari'];
        }
        if(isset($_POST['mulai'])){
                $mulai = $_POST['mulai'];
        }
        if(isset($_POST['selesai'])){
                $selesai = $_POST['selesai'];
        }
                 
        $tgl_daftar = date("Y-m-d");
        $wkt = date("H:i:s");
		
		
		
		$q_delete = "DELETE FROM jadwal_praktikum where siswa in (select id from siswa where kelas=$kelas) and materi=$materi";
		$result = mysql_query($q_delete);
		if($result){			
			$text_q_siswa = "SELECT * FROM siswa where kelas=$kelas";
			$q_siswa = mysql_query($text_q_siswa);
			while($dt_siswa = mysql_fetch_array($q_siswa)){
				$q = "INSERT INTO jadwal_praktikum
						(hari, jam_mulai, jam_selesai, siswa, materi) 
						VALUES('$hari', '$mulai', '$selesai', '".$dt_siswa['id']."', '$materi')";
				$result = mysql_query($q);
				if(!$result){
					echo 'failed query :'.$q ;
					die;
				}	
			
			}
			if($result){
				header("Location:../../admin_jadwal_praktikum.php?kelas=$kelas&materi=$materi");         										
			}
				
		}else{
			echo 'failed delete :'.$q_delete ;
		
		}
?>
